package Servlet.AdminServlet;

import Entity.Course;
import Service.AdminService.AdminService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
/*
负责管理员 改变课程审核状态 数据接口
 */
@WebServlet(value = "/changeCourseStatus")
public class ChangeCourseStatus extends HttpServlet {
    private AdminService adminService = new AdminService();

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setCharacterEncoding("utf-8");
        response.setContentType("application/json; charset=utf-8");

        String courseId = request.getParameter("courseId");
        int  status = Integer.parseInt(request.getParameter("status"));

        Course course = new Course();
        course.setStatus(status);
        course.setCourseId(courseId);


        int count = adminService.changeCourseStatus(course);

        PrintWriter out = response.getWriter();

        out.print(count);


    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}
